package com.taiji.dianthus.api.sys;

import com.taiji.dianthus.common.BusinessMessage;
import com.taiji.dianthus.service.sys.SysLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName SysLogController
 * @Description
 * @Author H.M
 * @Date 2020/7/2
 */
@Api(value = "系统日志api")
@RestController
@RequestMapping(value = "/api/log")
public class SysLogController {

    @Autowired
    private SysLogService sysLogService;

    @RequestMapping(value = "getLoginCountByDay")
    @ResponseBody
    @ApiOperation(value = "查询改天登录人数", notes = "查询改天登录人数接口")
    @ApiImplicitParam(name = "dayStr", value = "天数", dataType = "string", paramType = "query")
    public BusinessMessage getLoginCountByDay(HttpServletRequest request, String dayStr) {
        BusinessMessage message = new BusinessMessage();
        try {
            Integer count = sysLogService.countLoginByDay(dayStr);
            message.setData(count);
            message.setMsg("查询成功");
            message.setSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            message.setMsg("查询失败，系统异常");
            message.setData(0);
        } finally {
            return message;
        }

    }

    @RequestMapping(value = "getLoginCountByMonth")
    @ResponseBody
    @ApiOperation(value = "查询该月登录人数", notes = "查询该月登录人数接口")
    @ApiImplicitParam(name = "monthStr", value = "月份", dataType = "string", paramType = "query")
    public BusinessMessage getLoginCountByMonth(HttpServletRequest request, String monthStr) {
        BusinessMessage message = new BusinessMessage();
        try {
            Integer count = sysLogService.countLoginByMonth(monthStr);
            message.setData(count);
            message.setMsg("查询成功");
            message.setSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            message.setMsg("查询失败，系统异常");
            message.setData(0);
        } finally {
            return message;
        }
    }
}
